﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using AutoParsers.CustomExceptions;
using DL;
using AutoParsers.WebsiteParsers;

namespace AutoParsers
{
    public class ParseService
    {
        public ParsedCar ParseCar(string url)
        {
            var type = GetParserType(url);
            IAutoParser parserClass;
            switch (type)
            {
                case Parser.MYAUTO:
                    parserClass = new MyAutoGeParser();
                    break;
                case Parser.AUTO:
                    parserClass = new AutoGeParser();
                    break;
                case Parser.MYCAR:
                    parserClass = new MyCarGeParser();
                    break;
                case Parser.CAR:
                    parserClass = new CarGeParser();
                    break;
                case Parser.UNKNOWN:
                    throw new UnknownUrlException();
                   // break;
                default:
                    throw new InvalidUrlException();
                   // break;
            }
            return parserClass.ParseAuto(url);
        }

        private Parser GetParserType(string url)
        {
            if (url.ToLower().Contains("myauto.ge"))
            {
                return Parser.MYAUTO;
            }
            else if (url.ToLower().Contains("auto.ge"))
            {
                return Parser.AUTO;
            }
            else if (url.ToLower().Contains("mycar.ge"))
            {
                return Parser.MYCAR;
            }
            else if (url.ToLower().Contains("car.ge"))
            {
                return Parser.CAR;
            }
            else if (url.Contains("."))
            {
                return Parser.UNKNOWN;
            }
            else
            {
                throw new InvalidUrlException();
            }
        }



        public enum Parser
        {
            MYAUTO,
            AUTO,
            MYCAR,
            CAR,
            UNKNOWN
        }
    }
}
